﻿using System;
using System.Windows.Data;
using System.Windows.Media;
using GdiColor = System.Drawing.Color;

namespace GEPL.Converters
{
    /// <summary>
    /// Converts between System.Drawing.Color (used by the "turtle")
    /// and System.Windows.Media.Color (used by WPF controls, e.g. ColorPicker)
    /// </summary>
    public class GdiColorToMediaColorConverter : IValueConverter
    {
        public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            if (value is GdiColor)
            {
                var incolor = (GdiColor)value;
                var outcolor = Color.FromArgb(incolor.A, incolor.R, incolor.G, incolor.B);
                return outcolor;
            }
            return null;
        }

        public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            if (value is Color)
            {
                var incolor = (Color)value;
                var outcolor = GdiColor.FromArgb(incolor.A, incolor.R, incolor.G, incolor.B);
                return outcolor;
            }
            return null;
        }
    }
}